
#include <TVout.h>
#include <fontALL.h>
#include "sfdblogo.h"

TVout TV;

const int HOME_PIN = 13;

//Button state
int home_button_prev = 0;


//State variables
int home_score = 0;
int visitors_score = 0;

void setup() {
  TV.begin(PAL,120,96);
  
  //presentation();
  
  refresh();
  
  pinMode(HOME_PIN, INPUT); 
  
    

}

void loop() 
{
  boolean need_refresh = false;
  int home_button = digitalRead(HOME_PIN);
  
  //Check home_button
  if ((home_button == HIGH) && (home_button_prev == LOW)) 
  {
    home_score++;
    need_refresh = true;
    delay(50);
  }
  home_button_prev  = home_button;
  
  //!!!!!!
  
  if(need_refresh)
  {
    refresh();
  }
  
}

void refresh()
{
  TV.clear_screen();
  TV.select_font(font6x8);
  TV.print(8, 0, "HOME      VISITORS");
  TV.select_font(font8x8);
  TV.print(10, 10, home_score); 
  TV.print(80, 10, visitors_score);
  
  
}

void presentation()
{
   //Presentation
  TV.select_font(font6x8);
  TV.set_cursor(45,40);
  TV.println("Zulio\n");
  TV.delay(2000);
  TV.set_cursor(35,50);
  TV.println("presents\n");
  TV.delay(1500);
  TV.clear_screen();
  TV.bitmap(20,30,SFDBLogo);
  TV.delay(2000);
  TV.select_font(font8x8);
  TV.set_cursor(23,60);
  TV.println("SCOREBOARD\n");
  TV.delay(2000);
  TV.clear_screen(); 
}
